// Kony

#pragma once

#include "CoreMinimal.h"
#include "BaseGameplayTags.h"
#include "UI/WidgetController/BaseWidgetController.h"
#include "GameplayTagContainer.h"
#include "SpellMenuWidgetController.generated.h"

//发送两个布尔值的动态多播委托，用于广播选择法术按钮后 设置是否可升级按钮 和 是否可装备按钮
DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FSpellSelectedSignature, bool, bSpendPointsButtonEnabled, bool, bEquipButtonEnabled,FString, DescriptionString, FString, NextLevelDescriptionString);
//用于广播点击装备技能按钮 让装备技能按钮组件 显示待选动画广播
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FWaitForEquipSelectionSignature, const FGameplayTag&, AbilityType);
//分配技能到插槽完成广播，用于处理一些特效等 通知结束了停止等待
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSpellReassigedSignature, const FGameplayTag&, AbilityType);

//用于本地存储选择的技能
struct FSelectedAbility
{
	//能力标签
	FGameplayTag AbilityTag = FGameplayTag();
	//状态标签
	FGameplayTag StatusTag = FGameplayTag();
};

/**
 * 法术菜单小部件控制器 继承自基础小组件控制器
 */
UCLASS(BlueprintType, Blueprintable)
class GASC_HUANLING_API USpellMenuWidgetController : public UBaseWidgetController
{
	GENERATED_BODY()

public:
	//广播初始化值 子类重写
	virtual void BroadcastInitializeValues() override;
	//绑定回调函数到依赖项
	virtual void BindCallbacksToDependencies() override;
	//法术点变更委托
	UPROPERTY(BlueprintAssignable)
	FOnPlayerStatChangedSignature SpellPointsChanged;
	//委托选择按钮后 设置是否可升级按钮 和 是否可装备按钮
	UPROPERTY(BlueprintAssignable)
	FSpellSelectedSignature SpellSelectedDelegate;
	//分配技能到插槽完成广播，用于处理一些特效等 通知结束了停止等待
	UPROPERTY(BlueprintAssignable)
	FSpellReassigedSignature SpellReassigedDelegate;
	//等待装备委托
	UPROPERTY(BlueprintAssignable)
	FWaitForEquipSelectionSignature WaitForEquipDelegate;
	//停止等待装备委托
	UPROPERTY(BlueprintAssignable)
	FWaitForEquipSelectionSignature StopWaitForEquipDelegate;
	//用能力标签选择法术,判断当前法术是否可升级或可装备，并进行广播
	UFUNCTION(BlueprintCallable)
	void SpellSelected(const FGameplayTag& AbilityTag);
	//取消选择技能
	UFUNCTION(BlueprintCallable)
	void CancelSpellSelection();
	//升级技能按钮点击处理
	UFUNCTION(BlueprintCallable)
	void SpendPointButtonPressed();
	//点击装备按钮时处理函数
	UFUNCTION(BlueprintCallable)
	void EquipButtonPressed();
	//法术插槽处理
	UFUNCTION(BlueprintCallable)
	void SpellSlotPressed(const FGameplayTag& SlotTag, const FGameplayTag& AbilityType);
	//技能装备函数,能力标签、状态标签、按键输入插槽标签、上一个输入插槽标签
	void OnAbilityEquipped(const FGameplayTag& AbilityTag, const FGameplayTag& Status, const FGameplayTag& Slot, const FGameplayTag& PreviousSlot);

private:
	//设置是否可升级技能按钮 和 是否可装备技能按钮
	static void ShouldEnableButtons(const FGameplayTag& AbilityStatus, int32 SpellPoints, bool& bShouldEnableSpellPointsButton, bool& bShouldEnableEquipButton);
	//设置记录选择的技能 默认为None和锁定状态
	FSelectedAbility SelectedAbility = {FBaseGameplayTags::Get().Abilities_None, FBaseGameplayTags::Get().Abilities_Status_Locked };
	//当前技能点数
	int32 CurrentSpellPoints = 0;
	//等待用户选择装备的技能位置变量,点击装备按钮后 为true 等待选择，选择后为false
	bool bWaitingForEquipSelect = false;
	//选中的槽位
	FGameplayTag SelectedSlot;
};
